local extension = Package:new("other")
extension.extensionName = "king"
local U = require "packages/utility/utility"


Fk:loadTranslationTable{
    ["other"] = "其他",
  } 



--[[local o__zhajinhua = General(extension, "o__zhajinhua", "god", 5)
  local zhajinhua = fk.CreateActiveSkill{
    name = "zhajinhua",
    can_use = function(self,  player, effect,room)
      return  player:getMark("@yin__baonu") > 11
    end,
    card_num = 3,
    target_num = 0,
    card_filter = Util.FalseFunc,
    on_use = function(self, event, target, player, data)
    local room = player.room
    local card = room:askForDiscard(player, 3, 3, true, self.name, false, ".", "#shanjia-discard:::".. true)
    room:throwCard(card, self.name, player, player)
    local cards ={}
    local cards = U.turnOverCardsFromDrawPile(player, 3, self.name)
    local num1 = Fk:getCardById(cards{1}).number
    local num2 = Fk:getCardById(cards{2}).number
    local num3 = Fk:getCardById(cards{3}).number
    local suit = Fk:getCardById(cards).suit


    if (num1 == num2 == num3)  then --豹子
      room:drawCards(player, 6, self.name)
      local tos = room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1, "#zhajinhua-damage", self.name, true)
      room:damage{
        from = player,
        to = tos,
        damage = 1,
        skillName = self.name,
      }
    elseif #suit == 1 and (num1+1 ==num2 and num2+1 ==num3) or (num1+1 ==num3 and num3+1 ==num2) or (num2+1 ==num1 and num1+1 ==num3) or (num2+1 ==num3 and num3+1 ==num1) or (num3+1 ==num1 and num1+1 ==num2) or (num3+1 ==num2 and num2+1 ==num1) then --同花顺
      room:drawCards(player, 6, self.name)
      local to = room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1, "#zhajinhua-drawCards", self.name, true)
      room:drawCards(player, 3, self.name)
    elseif #suit ~= 1 and (num1+1 ==num2 and num2+1 ==num3) or (num1+1 ==num3 and num3+1 ==num2) or (num2+1 ==num1 and num1+1 ==num3) or (num2+1 ==num3 and num3+1 ==num1) or (num3+1 ==num1 and num1+1 ==num2) or (num3+1 ==num2 and num2+1 ==num1) then --顺子
      room:drawCards(player, 3, self.name)
    elseif (num1 == 2 and num2 == 3 and num3 == 5) and #suit ~= 1  then --235
      room:drawCards(player, 6, self.name)
      local to = room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1, "#zhajinhua-drawCards", self.name, true)
      room:drawCards(player, 3, self.name)
      local tos = room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1, "#zhajinhua-damage", self.name, true)
      room:damage{
        from = player,
        to = tos,
        damage = 1,
        skillName = self.name,
      }
    elseif (suit1 == suit2 == suit3) and (num1+1 ==num2 and num2+1 ~=num3) or (num1+1 ==num3 and num3+1 ~=num2) or (num2+1 ==num1 and num1+1 ~=num3) or (num2+1 ==num3 and num3+1 ~=num1) or (num3+1 ==num1 and num1+1 ~=num2) or (num3+1 ==num2 and num2+1 ~=num1) then --同花
      local to = room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1, "#zhajinhua-drawCards", self.name, true)
      room:drawCards(player, 3, self.name)
    elseif (num1 == num2 and num1 ~= num3 ) or (num2 == num3 and num2 ~= num1) or (num1 == num3 and num1 ~= num2) and (suit1~=suit2 or suit1~=suit3 or suit2~=suit3) then --对子
      room:drawCards(player, 2, self.name)
    else --杂牌
      end
    end,
  }
  o__zhajinhua:addSkill(zhajinhua)
  Fk:loadTranslationTable{
    ["o__zhajinhua"] = "炸金花",
    ["zhajinhua"] = "炸金花",
    [":zhajinhua"] = "弃置三张牌，然后展示牌堆顶三张牌，根据点数执行相应效果",

    ["#zhajinhua-damage"] = "选择一名角色对其造成一点伤害",
    ["#zhajinhua-drawCards"] = "选择一名角色令其摸三张牌",

}]]





local xing__zhugeliang = General:new(extension,"xing__zhugeliang","shu",7)

local x_qixing = fk.CreateTriggerSkill{
  name = "x_qixing",
  mute = true,
  events = {fk.RoundStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.RoundStart then
        return true
      else
        return player == target and player:getHandcardNum() <= player.hp and player:getMark("x_qixing_defensive-turn") == 0 and
        #player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function (e)
          local damage = e.data[5]
          return damage and damage.to == player
        end, Player.HistoryTurn) == 0
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player, self.name, "drawcard")
      local x = player.maxHp - player:getHandcardNum()
      if x > 0 and room:askForSkillInvoke(player, self.name, nil, "#x_qixing-draw:::" .. tostring(x)) then
        room:drawCards(player, x, self.name)
        if player.dead then return false end
      end
      if player:isNude() then return false end
      local cards = room:askForCard(player, 1, 998, true, self.name, true, ".", "#x_qixing-cards")
      x = #cards
      if x == 0 then return false end
      table.shuffle(cards)
      local positions = {}
      local y = #room.draw_pile
      for _ = 1, x, 1 do
        table.insert(positions, math.random(y+1))
      end
      table.sort(positions, function (a, b)
        return a > b
      end)
      local moveInfos = {}
      for i = 1, x, 1 do
        table.insert(moveInfos, {
          ids = {cards[i]},
          from = player.id,
          toArea = Card.DrawPile,
          moveReason = fk.ReasonJustMove,
          skillName = self.name,
          drawPilePosition = positions[i],
        })
      end
      room:moveCards(table.unpack(moveInfos))
      if player.dead then return false end
      cards = room:getCardsFromPileByRule(".|7", x)
      if x > #cards then
        table.insertTable(cards, room:getCardsFromPileByRule(".|7", x - #cards, "discardPile"))
      end
      if #cards > 0 then
        player.room:moveCards({
          ids = cards,
          to = player.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonPrey,
          proposer = player.id,
          skillName = self.name,
          moveMark = "@@x_qixing-inhand-round",
        })
      end
    else
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player, self.name, "defensive")
      room:setPlayerMark(player, "x_qixing_defensive-turn", 1)
      data.damage = data.damage - 1
    end
  end,

}
local x_qixing_maxcards = fk.CreateMaxCardsSkill{
  name = "#x_qixing_maxcards",
  exclude_from = function(self, player, card)
    return card:getMark("@@x_qixing-inhand-round") > 0
  end,
}
local x_qixing_drawCards = fk.CreateTriggerSkill{
  name = "#x_qixing_drawCards",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return 
    player:hasSkill(x_qixing) and  data.card.number == 7
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, x_qixing.name)
  end,
}

local rangxing = fk.CreateTriggerSkill{           
  name = "rangxing",
  frequency = Skill.Wake,
  events = {fk.EnterDying},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function (self, event, target, player, data)
    return player.hp < 1
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:recover{num = 7 - player.hp, who = player, recoverBy = player, skillName = self.name}
    if not player.dead then
      room:setPlayerMark(player, "_rangxing", 8)
  
    end
  end,

  refresh_events = {fk.TurnEnd},
  can_refresh = function (self, event, target, player, data)
    return player:getMark("_rangxing") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local player = room:getPlayerById(effect.from)
    local mark = player:getMark("_rangxing")
    room:setPlayerMark(player, "_rangxing", mark - 1)
    if mark == 1    then
     room:killPlayer({who = player.id,})
    end
  end,
}
x_qixing:addRelatedSkill(x_qixing_maxcards)
x_qixing:addRelatedSkill(x_qixing_drawCards)
xing__zhugeliang:addSkill(x_qixing)
xing__zhugeliang:addSkill(rangxing)
Fk:loadTranslationTable{
  ["xing__zhugeliang"] = "星诸葛亮",
  ["xing"] = "星",
  ["designer:xing__zhugeliang"] = "妄生",
  ["x_qixing"] = "七星",
  ["#x_qixing-draw"] = "七星：是否将手牌补至体力上限（摸%arg张牌）",
  ["#x_qixing-cards"] = "七星：你可将任意张牌随机置入牌堆，然后获得等量张点数为7的牌",
  ["@@x_qixing-inhand-round"] = "七星",
  [":x_qixing"] = "锁定技，每轮开始时，你可以将手牌摸至体力上限，然后将任意张牌随机置入牌堆，从牌堆或弃牌堆中获得等量的点数为7的牌，"..
  "这些牌此轮内不计入你的手牌上限。当点数为7的牌被使用或打出时，摸一张牌.",
  ["rangxing"] = "禳星",
  [":rangxing"] = "觉醒技，当你进入濒死状态时，你将体力回复至7点，然后于此回合与之后的7个回合后，你死亡。",


}


--[[local o__wangfeng = General:new(extension,"o__wangfeng","god",4)
local o__wangfengdinglv = fk.CreateActiveSkill{
  name = "o__wangfengdinglv",
}
o__wangfeng:addSkill(o__wangfengdinglv)
Fk:loadTranslationTable{
  ["o__wangfeng"] = "汪峰",
  ["o__wangfengdinglv"] = "汪峰定律",
  [":o__wangfengdinglv"] = "锁定技，你的回合外，场上其他玩家使用牌结算后，你可弃置一张牌，视为使用一张同名牌，然后摸一张牌；你的回合内，当你使用牌指定目标后，场上其他玩家可以选择是否弃置一张同名牌，若其他玩家皆未弃牌，那么此牌不可响应，并在结算后摸X张牌。（X为场上其他玩家数量）"



}]]
local o__jvshou = General(extension, "o__jvshou", "qun", 2, 3)
o__jvshou.shield = 3

Fk:loadTranslationTable{
  ["o__jvshou"] = "沮授吗？",
}

local o__jianying = fk.CreateViewAsSkill{
  name = "o__jianying",
  prompt = "#o__jianying-active",
  interaction = function()
    local names, all_names = {} , {}
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id)
      if card.type == Card.TypeBasic and not card.is_derived and not table.contains(all_names, card.name) then
        table.insert(all_names, card.name)
        local to_use = Fk:cloneCard(card.name)
        if Self:canUse(to_use) and not Self:prohibitUse(to_use) then
          table.insert(names, card.name)
        end
      end
    end
    if #names == 0 then return false end
    return UI.ComboBox { choices = names, all_choices = all_names }
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  view_as = function(self, cards)
    if not self.interaction.data or #cards ~= 1 then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)

    local suitstrings = {"spade", "heart", "club", "diamond"}
    local suits = {Card.Spade, Card.Heart, Card.Club, Card.Diamond}
    local colors = {Card.Black, Card.Red, Card.Black, Card.Diamond}
    local suit = Self:getMark("o__jianying_suit-phase")
    if table.contains(suitstrings, suit) then
      card.suit = suits[table.indexOf(suitstrings, suit)]
      card.color = colors[table.indexOf(suitstrings, suit)]
    end

    card.skillName = self.name
    return card
  end,
}
local o__jianying_trigger = fk.CreateTriggerSkill{
  name = "#o__jianying_trigger",
  events = {fk.CardUsing},
  mute = true,
  main_skill = o__jianying,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(o__jianying)  and
    (data.extra_data or {}).m_ex__jianying_triggerable
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(o__jianying.name)
    player.room:notifySkillInvoked(player, o__jianying.name, "drawcard")
    player:drawCards(1, o__jianying.name)
  end,

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(o__jianying, true) 
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if data.card:getSuitString() ~= player:getMark("o__jianying_suit") and
        (data.card.number ~= player:getMark("o__jianying_number") and data.card.number ~= 0) then
      data.extra_data = data.extra_data or {}
      data.extra_data.m_ex__jianying_triggerable = true
    end
    if data.card.suit == Card.NoSuit then
      room:setPlayerMark(player, "o__jianying_suit", 0)
    else
      room:setPlayerMark(player, "o__jianying_suit", data.card:getSuitString())
    end
    room:setPlayerMark(player, "o__jianying_number", data.card.number)

    room:setPlayerMark(player, "@o__jianying_record", {data.card:getSuitString(true), data.card:getNumberStr()})
  end,
}

o__jianying:addRelatedSkill(o__jianying_trigger)

Fk:loadTranslationTable{
  ["o__jianying"] = "渐营吗？",
  ["#o__jianying_trigger"] = "渐营吗？",
  [":o__jianying"] = "当你使用牌时，若此牌与你于此阶段内使用的上一张牌点数和花色不相同，你可以摸一张牌。出牌阶段，你可以将一张牌当任意一种基本牌使用，若你于此阶段内使用的上一张牌有花色，则此牌花色视为你本回合使用的上一张牌的花色。",
  ["#o__jianying-active"] = "发动渐营，将一张牌转化为任意基本牌使用",
  ["@o__jianying_record"] = "渐营吗？",
  ["$o__jianying"] = "得胜已是定局"
}
o__jvshou:addSkill(o__jianying)
o__jvshou:addSkill("shibei")


return extension  